<?php
namespace app\api\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;
use app\common\model\Nav as NavModel;
use think\Db;

/**
 * 首页首页
 * Class Index
 * @package app\admin\controller
 */
class Index extends HomeBase
{
    protected function _initialize(){
        parent::_initialize();
        $this->nav_model = new NavModel();
    }

    /**
    *顶部导航栏选取
    *@return json
    **/
    public function topNav()
    {
        $list = $this->nav_model->where('pid',0)->where('status',1)->select();
        if($list){
            $this->apiSuccess($list);
        }else{
            $this->apiError('没有查到信息');
        }
    }

    /**
    *其他导航栏选取
    *@return json
    **/
    public function elseNav()
    {
        $data = $this->request->param();
        $pid = $data['pid'];
        $list = $this->nav_model->where('status',1)->select();
        if ($list) {
            $list1 = array2level($list,$pid);
            if($list1){
                $this->apiSuccess($list1);
            }else{
                $this->apiError('没有查到信息');
            }
        }else{
            $this->apiError('没有查到信息');
        }
    }

}